﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using WpfGraphing;
using WpfGraphing.Collections;
using WpfGraphing.Style;

namespace WpfGraphingTest
{
    public class ChartBasicDetailsViewModel : AbstractViewModel<ChartBasicDetailsViewModel>
    {
        string title;
        public string Title
        {
            get { return title; }
            set
            {
                title = value;
                OnPropertyChanged("Title");
            }
        }

        string xAxisTitle;
        public string XAxisTitle
        {
            get { return xAxisTitle; }
            set
            {
                xAxisTitle = value;
                OnPropertyChanged("XAxisTitle");
            }
        }

        string yAxisTitle;
        public string YAxisTitle
        {
            get { return yAxisTitle; }
            set
            {
                yAxisTitle = value;
                OnPropertyChanged("YAxisTitle");
            }
        }

        bool showLabels;
        public bool ShowLabels
        {
            get { return showLabels; }
            set
            {
                showLabels = value;
                OnPropertyChanged("ShowLabels");
            }
        }

        bool autoUpdate;
        public bool AutoUpdate
        {
            get { return autoUpdate; }
            set
            {
                autoUpdate = value;
                OnPropertyChanged("AutoUpdate");
            }
        }


        ChartStyleGridLines chartStyle;
        public ChartStyleGridLines ChartStyle
        {
            get { return chartStyle; }
            set
            {
                chartStyle = value;
                OnPropertyChanged("ChartStyle");
            }
        }

        BarChartDataList barSeries;
        public BarChartDataList BarSeries
        {
            get { return barSeries; }
            set
            {
                barSeries = value;
                OnPropertyChanged("BarSeries");
            }
        }

        public ChartBasicDetailsViewModel()
        {
            Application.Current.Dispatcher.Invoke((Action)(() =>
            {
                this.AutoUpdate = true;
                this.barSeries = new BarChartDataList();
                this.chartStyle = new ChartStyleGridLines();
                this.chartStyle.GridLinePattern = WpfGraphing.Style.ChartStyle.ChartGridLinePattern.Dash;
            }));
        }

        public void Setup(string title, string _xAxisTitle, string _yAxisTitle, BarChartDataList.ChartBarType chartType, WpfGraphing.Style.ChartStyle.ChartGridLinePattern gridLinePattern, bool activeToolTip = false, bool labelsVisible = false)
        {
            Application.Current.Dispatcher.Invoke((Action)(() =>
            {
                this.AutoUpdate = false;
                this.Title = title;
                this.XAxisTitle = _xAxisTitle;
                this.YAxisTitle = _yAxisTitle;
                this.chartStyle.XTickLabels.Clear();
                this.barSeries.ActiveToolTip = true;
                this.barSeries.LabelValuesVisibility = false;
                this.barSeries.BarType = chartType;
                this.BarSeries.DataList.Clear();
                this.chartStyle.GridLine = WpfGraphing.Style.ChartStyle.ChartGridLine.Horizontal;
                this.ChartStyle.GridLinePattern = gridLinePattern;
            }));
        }

        public void AddDataListItem(BarDataSeries bar)
        {
            Application.Current.Dispatcher.Invoke((Action)(() =>
            {
                this.BarSeries.DataList.Add(bar);
                OnPropertyChanged("DataList");
            }));
        }

        public void CreateGraph()
        {
            Application.Current.Dispatcher.Invoke((Action)(() =>
            {
                this.AutoUpdate = true;
                this.BarSeries.CreatGraph(this.chartStyle);
            }));
        }

    }

}
